home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / main / ae.c next >
Text File  |  1994-04-14  |  3KB  |  105 lines

  1. /*
  2. *    ae.c
  3. *    Code to handle the AppleEvents we recognize
  4. *****************************************************************
  5. *    NCSA Telnet for the Macintosh                                *
  6. *                                                                *
  7. *    National Center for Supercomputing Applications                *
  8. *    Software Development Group                                    *
  9. *    152 Computing Applications Building                            *
  10. *    605 E. Springfield Ave.                                        *
  11. *    Champaign, IL  61820                                        *
  12. *                                                                *
  13. *    Copyright (c) 1986-1994,                                    *
  14. *    Board of Trustees of the University of Illinois                *
  15. ****************************************************************/
  16.  
  17. #include <GestaltEqu.h>
  18. #include <AppleEvents.h>
  19.  
  20. #include "TelnetHeader.h"
  21. #include "ae.proto.h"
  22. #include "Sets.proto.h"            // For readconfig proto
  23. #include "menuseg.proto.h"        // For HandleQuit proto
  24. #include "debug.h"
  25.  
  26. SIMPLE_UPP(MyHandleODoc, AEEventHandler);
  27. pascal OSErr  MyHandleODoc (AppleEvent *theAppleEvent, AppleEvent* reply, long
  28.                                                         handlerRefCon)
  29. {
  30.     FSSpec        myFSS;
  31.     AEDescList    docList;
  32.     OSErr        err;
  33.     long        index, itemsInList;
  34.     Size        actualSize;
  35.     AEKeyword    keywd;
  36.     DescType    returnedType;
  37.     FInfo        fileInfo;
  38.     
  39.     if (err = AEGetParamDesc (theAppleEvent, keyDirectObject, typeAEList, &docList))
  40.         return err;
  41.  
  42.     // check for missing parameters
  43.     if (err = MyGotRequiredParams (theAppleEvent))
  44.         return err;
  45.  
  46.     // count the number of descriptor records in the list
  47.     if (err = AECountItems (&docList, &itemsInList))
  48.         return err;
  49.  
  50.     for (index = 1; index <= itemsInList; index++) {
  51.             err = AEGetNthPtr (&docList, index, typeFSS, &keywd, &returnedType, 
  52.                                 (Ptr) &myFSS, sizeof(myFSS), &actualSize);
  53.             if (err) return err;
  54.             
  55.             FSpGetFInfo(&myFSS, &fileInfo);        /* make sure it's a data file */
  56.             if (fileInfo.fdCreator == creator && fileInfo.fdType == filetype)
  57.                 readconfig(myFSS);        // Read the actual set
  58.     }
  59.  
  60.     err = AEDisposeDesc (&docList);
  61.     return noErr;
  62. }
  63.  
  64. SIMPLE_UPP(MyHandlePDoc, AEEventHandler);
  65. pascal OSErr  MyHandlePDoc (AppleEvent *theAppleEvent, AppleEvent *reply, long
  66.                                                         handlerRefCon)
  67. {
  68.     // We don't print files.
  69.     return (errAEEventNotHandled);
  70. }
  71.  
  72. SIMPLE_UPP(MyHandleOApp, AEEventHandler);
  73. pascal OSErr  MyHandleOApp (AppleEvent *theAppleEvent, AppleEvent *reply, long
  74.                                                         handlerRefCon)
  75. {
  76.     // Don't need to do anything for OApp.
  77.     return noErr;
  78. }
  79.  
  80. SIMPLE_UPP(MyHandleQuit, AEEventHandler);
  81. pascal OSErr  MyHandleQuit (AppleEvent *theAppleEvent, AppleEvent *reply, long
  82.                                                         handlerRefCon)
  83. {
  84.     if (HandleQuit())
  85.         return(-128);    // userCancelledErr
  86.             
  87.     return(noErr);    
  88. }
  89.  
  90. OSErr MyGotRequiredParams (AppleEvent *theAppleEvent)
  91. {
  92.     DescType    returnedType;
  93.     Size        actualSize;
  94.     OSErr        err;
  95.  
  96.     err = AEGetAttributePtr (theAppleEvent, keyMissedKeywordAttr,
  97.                                     typeWildCard, &returnedType, nil, 0,
  98.                                     &actualSize);
  99.     if (err == errAEDescNotFound)    // you got all the required parameters
  100.             return noErr;
  101.     else if (!err)            // you missed a required parameter
  102.             return errAEEventNotHandled;
  103.     else                    // the call to AEGetAttributePtr failed
  104.             return err;
  105. }